<?php

/**
 * plan actions.
 *
 * @package    vtns
 * @subpackage plan
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class plansActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
	  $cms_category_news = Doctrine_Core::getTable('VTNSCmsCategory')->findOneByAlias('plans');
	  
	  $q = Doctrine_Query::create()
			 ->select('c.*')
			 ->from('VTNSCmsCategory c')
			 ->addWhere('c.parent_id = ?', $cms_category_news->cms_category_id);
			 
	  $cms_categories = $q->fetchArray();
	  
	  foreach ($cms_categories as $cms_category)
	  {
		  $c = Doctrine_Query::create()
				 ->select('c.*')
				 ->from('VTNSCms c')
				 ->addWhere('c.cms_category_id = ?', $cms_category['cms_category_id']);
		  $this->cms_list = $c->fetchArray();
		  if (sizeof($this->cms_list) == 1)
			  foreach ($this->cms_list as $cms_temp)
			  	$this->cms = Doctrine_Core::getTable('VTNSCms')->find($cms_temp['cms_id']);
		  break;
	  }
	  
	  $this->cms_categories = $cms_categories;
	  $this->setTitle("Dự án");
	  return SfView::SUCCESS;
  }
  
  public function executePermalink(sfWebRequest $request) 
  {
	  $cms_category_id = $request->getParameter("cms_category_id");
	  $cms_id = $request->getParameter("cms_id");
	  
	  $this->cms_category_id = $cms_category_id;
	  
	  // Get list category
	  $cms_category_news = Doctrine_Core::getTable('VTNSCmsCategory')->findOneByAlias('plans');
		  
	  $q = Doctrine_Query::create()
			 ->from('VTNSCmsCategory c')
			 ->addWhere('c.parent_id = ?', $cms_category_news->cms_category_id);
	  $this->cms_categories = $q->fetchArray();
	  
	  if (isset($cms_id))
	  {
		  $this->act = "cms_view";  
		  $this->cms = Doctrine_Core::getTable('VTNSCms')->find($cms_id);
	  }
	  else
	  {
		  $q = Doctrine_Query::create()
 				 ->from('VTNSCms c')
 				 ->addWhere('c.cms_category_id = ?', $cms_category_id);
				 
		  $this->cms_arr = $q->fetchArray();
		  if (sizeof($this->cms_arr) == 1)
			  foreach ($this->cms_arr as $cms_temp)
			  	$this->cms = Doctrine_Core::getTable('VTNSCms')->find($cms_temp['cms_id']);
		  $this->act = "cms_list";
	  }
	  $this->setTitle("Dự án");
	  return SfView::SUCCESS;
  }
}
